/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities1;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author takamflore
 */
@Entity
@Table(catalog = "meteoCalDB", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "InvitationRequest.findAll", query = "SELECT i FROM InvitationRequest i"),
    @NamedQuery(name = "InvitationRequest.findById", query = "SELECT i FROM InvitationRequest i WHERE i.id = :id"),
    @NamedQuery(name = "InvitationRequest.findByAccepted", query = "SELECT i FROM InvitationRequest i WHERE i.accepted = :accepted")})
public class InvitationRequest implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull(message = "May not be empty")
    @Column(nullable = false)
    private boolean accepted;
    @JoinColumn(name = "User", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private Users user;
    @JoinColumn(name = "Event", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private Event event;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "invitationRequest")
    private Collection<Notify> notifyCollection;

    public InvitationRequest() {
    }

    public InvitationRequest(Integer id) {
        this.id = id;
    }

    public InvitationRequest(Integer id, boolean accepted,int idEvent) {
        this.id = id;
        this.event.setId(idEvent);
        this.accepted = accepted;
    }
    // new invitation
    public InvitationRequest(int eventId, int userid,boolean accepted) {
        this.event.setId(eventId);
        this.accepted = accepted;
        this.user.setId(userid);
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public boolean getAccepted() {
        return accepted;
    }

    public void setAccepted(boolean accepted) {
        this.accepted = accepted;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    @XmlTransient
    public Collection<Notify> getNotifyCollection() {
        return notifyCollection;
    }

    public void setNotifyCollection(Collection<Notify> notifyCollection) {
        this.notifyCollection = notifyCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof InvitationRequest)) {
            return false;
        }
        InvitationRequest other = (InvitationRequest) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.InvitationRequest[ id=" + id + " ]";
    }
    
}
